<?php

/**
 * JingYao-backend
 *
 * @link     https://gitee.com/wang-zhihui-release/jingyao-backend
 * @apiDocument https://gitee.com/wang-zhihui-release/jingyao-backend/wikis/
 */

namespace App\Rules;

use Illuminate\Contracts\Validation\Rule;

class AssessCreateRule implements Rule
{
    protected $message;

    /**
     * Create a new rule instance.
     */
    public function __construct()
    {
    }

    /**
     * Determine if the validation rule passes.
     *
     * @param string $attribute
     * @param mixed $value
     * @return bool
     */
    public function passes($attribute, $value)
    {
        $mustColumns = [
            // 'title',
            'name',
            'description',
            'type',
        ];
        foreach ($mustColumns as $mustColumn) {
            if (! isset($value[$mustColumn])) {
                $this->message = '字段 ' . $mustColumn . ' 缺失';
                return false;
            }
        }
        return true;
    }

    /**
     * Get the validation error message.
     *
     * @return string
     */
    public function message()
    {
        return $this->message;
    }
}
